<?php
require "../common/user_online.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>EbookAZ</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<?php require "../components/head.php" ?>
</head>
<body onload="MakeCurrentPage(1)">
<div id="container">
	<?php require "../components/admin_menu.php" ?>
	<?php require "../components/admin_header.php" ?>
	<div id="content">
		<?php require "../components/content_left.php"?>
		<div id="content_right">
		
		<?php
		
		//Kết nối csdl
		require "../common/db.inc";
		$conn = new mysqli($host, $username, $password, $dbname);	
		$conn->query("set names 'utf8'");		
		//check connection
		if (mysqli_connect_errno()) {
		    printf("Connect failed: %s\n", mysqli_connect_error());
		    exit();
		}
	
		$sql = "call sp_GetAllUncheckedEbook();";
		$num_rows = mysqli_num_rows($conn->query($sql));
		
		if(isset ( $_GET["page"] ))
			$page = $_GET["page"];
		else
			$page = 1;
			
		$rows_per_page = 10;
		$pages_per_page = 5;
		$offset = ($page-1)*$rows_per_page;		
		?>
		<div align='center'>
			<h1>Có <?php echo $num_rows;?> ebook đang chờ bạn xét duyệt</h1><br />
		
		<?php
		$conn = new mysqli($host, $username, $password, $dbname);	
		$conn->query("set names 'utf8'");
		if (mysqli_connect_errno()) {
		    printf("Connect failed: %s\n", mysqli_connect_error());
		    exit();
		}	

		$sql = "call sp_GetUncheckedEbook($offset, $rows_per_page);";
		$result = $conn->query($sql);
		$count =  mysqli_num_rows($result);
		$i = 0;
		
		echo "<table width='100%' cellspacing='0' border='1'>";		
	    while ($row = $result->fetch_row()) 
		{
			$id	= $row[0];
			$title = $row[1];
			$fileupload = $row[2];		
			$type = $row[3];
			$description = $row[4];
			$author = $row[5];
			$publisher = $row[6];
			$pagenum = $row[7];
			$img = $row[8];
			$size = $row[9];
			$category = $row[10];
			$updatedate = $row[11];
			$userid = $row[12]; 
			
			//lay loai file
			$lastpos = strrpos($file_up, '.');
			$filetype = substr($file_up, $lastpos + 1, strlen($file_up));
			
			//ngày tháng năm
			$arr = date_parse($updatedate);
			$ngay = $arr['day'];
			$thang = $arr['month'];
			$nam = $arr['year'];
			if ($ngay < 10)
				$ngay = "0" . $ngay;
			if ($thang < 10)
				$thang = "0" . $thang;
			$updatedate = $ngay . "/" . $thang . "/" . $nam;
			
			if($i%2 == 0)
				echo "<tr>";
			echo "<td valign='top' width='50%'>";
			echo "<a href='XemChiTietSach.php?id=$id'>";
			echo "<a href='uncheckedebook_detail.php?id=$id'><img align='left' src='$image$img' style='padding:3px 10px 3px 5px' width='100px' height='150px' alt='EBook'/></a>";
			echo "</a>";
			echo "<table><tr><td>";
			echo "<a href='uncheckedebook_detail.php?id=$id'><b>$title</b></a><br/>";
			echo "<label><i>Tác giả: </i>$author</label><br/>";
			echo "<label><i>Loại file: </i>$filetype</label><br/>";
			echo "<label><i>Kích thước: </i>$size Kb</label><br/>";
			//echo "<label><i>Số trang: </i>$pagenum</label><br/>";
			echo "<label><i>Ngày upload: </i>$updatedate</label><br/>";
			echo "<label><i>Mana: </i><input type='text' name='txtMana' value='100' size='2px' readOnly=true/>&nbsp;<img src='../images/questionmark.gif' title='Xem chi tiết trước khi cập nhật mana'/></label><br/><br/>";
			echo "<a href='uncheckedebook_detail.php?id=$id'>Xem chi tiết</a>&nbsp;&nbsp;";
			echo "<input type='button' value='Duyệt' onClick='CheckBook({$id})'></input>";
			echo "</td></tr></table>";
			echo "</td>";
			if($i % 2 == 1)
				echo "</tr>";
			else if($i == $count-1)
			{
				for($j=0;$j<2-($count%2);$j++)
					echo "<td>&nbsp;</td>";
				echo "</tr>";
			}
			$i++;
		}
		echo "</table>";
		
		include "../common/paging.php";
		$listpage = paging("home.php", $rows_per_page, $pages_per_page, $num_rows, $page, "");
		echo $listpage;
	    /* free result set */
	    $result->close();
		$conn->close();
		?>
			
		</div>
	</div>
	<?php require "../components/footer.php" ?>
</div>
</body>
</html>
